#if !defined(___STD_C)
#define ___STD_C
#include "std.h"


static tProg _prg;
tProg *prg=&_prg;


xx msg(N1 msg,Str fmt,...)
{ Ptr pp=(Ptr)(&fmt+1);
  if (!prg)
  { fprintf(stderr,"Error: msg: NULL prg\n");
    return;
  }
  if (msg>prg->msg) return;
  vfprintf(prg->fo,fmt,pp);
  fflush(prg->fo);
}

xx dumpN1(Str s1,N1 *dd)
{ N2 i1; for (i1=0;i1<64;++i1)
  { if (!i1)
      DEB1("\n[........] (%s):\n",s1);
    if ((i1&7)==0)
      DEB0("[........] ");
    DEB1("  %u",(N2)*(dd++));
    if ((i1&7)==7)
      DEB0("\n");
  }
  DEB0("[........] ");
}

xx dumpI2(Str s1,I2 *dd)
{ N2 i1; for (i1=0;i1<64;++i1)
  { if (!i1)
      DEB1("\n[........] (%s):\n",s1);
    if ((i1&7)==0)
      DEB0("[........] ");
    DEB1("  %i",*(dd++));
    if ((i1&7)==7)
      DEB0("\n");
  }
  DEB0("[........] ");
}

xx dumpI4(Str s1,I4 *dd)
{ N2 i1; for (i1=0;i1<64;++i1)
  { if (!i1)
      DEB1("\n[........] (%s):\n",s1);
    if ((i1&7)==0)
      DEB0("[........] ");
    DEB1("  %li",*(dd++));
    if ((i1&7)==7)
      DEB0("\n");
  }
  DEB0("[........] ");
}

xx dumpN4(Str s1,N4 *dd)
{ N2 i1; for (i1=0;i1<64;++i1)
  { if (!i1)
      DEB1("\n[........] (%s):\n",s1);
    if ((i1&7)==0)
      DEB0("[........] ");
    DEB1("  %08lX",*(dd++));
    if ((i1&7)==7)
      DEB0("\n");
  }
  DEB0("[........] ");
}

xx dumpR4(Str s1,R4 *dd)
{ N2 i1; for (i1=0;i1<64;++i1)
  { if (!i1)
      DEB1("\n[........] (%s):\n",s1);
    if ((i1&7)==0)
      DEB0("[........] ");
    DEB1("  %f",*(dd++));
    if ((i1&7)==7)
      DEB0("\n");
  }
  DEB0("[........] ");
}

Ptr MemGet(N4 len)
{ if (!len) return (NULL);
  return (malloc(len));
}

xx MemRel(Ptr p)
{ if (p) free(p);
}

I4 MemCpy(Str s1,Str s2,N4 l)
{ if (l && (!s1 || !s2))
    return (-1l);
  if (!l || s1==s2) return (0);
  if (s1>s2)
  { while (l--) *(s2++)=*(s1++);
  } else
  { s1+=l-1; s2+=l-1;
    while (l--) *(s2--)=*(s1--);
  }
  return (0);
}

Str StrCmp(Str s1,Str s2)
{ if (!s1 || !s2)
  { if (s2) s1=s2;
    if (s1 && *s1)
      return (s1);
    return (NULL);
  }
  for (;*s1 && *s2;++s1,++s2)
    if (*s1!=*s2) return (s1);
  if (*s1!=*s2) return (s1);
  return (NULL);
}

I4 StrLen(Str s1)
{ I4 i1;
  if (!s1) return (0);
  for (i1=0;*(s1++);++i1);
  return (i1);
}

R4 RoundR4(R4 r1)
{ return ((R4)floor(r1+0.5));
}


#endif
